<?php
/*
* Start output buffering
*/
ob_start();

/*
* Set error reporting to the level to which Zend Framework code must comply.
*/
error_reporting( E_ALL | E_STRICT );

ini_set('display_startup_errors', 0);
ini_set('display_errors', 0);

/*
* Set default timezone
*/
date_default_timezone_set('Europe/London');


defined('APPLICATION_PATH')
    or define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

define('APPLICATION_ENV', 'development');


/*
 * Set the include path
 */
$root  = realpath(dirname(__FILE__) . '/../');
$library = $root . '/library/';
$tests = $root . '/tests';
$application = $root . '/application';
$paths = array(
    "$library",
    "$tests",
    "$application",
    get_include_path()
);
set_include_path(implode(PATH_SEPARATOR, $paths));

/**
 * Autoloader helpers
 */
function _Autoloader_SetUp() {
    require_once 'Zend/Loader/Autoloader.php';
    $loader = Zend_Loader_Autoloader::getInstance();
    $loader->registerNamespace('RedCross_');
    $loader->registerNamespace('Doctrine_');
    $loader->registerNamespace('ZendX_');
    $loader->registerNamespace('ZFDebug_');

    $resourceLoader = new Zend_Application_Module_Autoloader(array(
            'namespace' => 'Core',
            'basePath'  => APPLICATION_PATH . '/modules/core',
        )
    );
    $resourceLoader->addResourceType('gateway', 'gateways/', 'Gateway');

    $manager = Doctrine_Manager::getInstance();
    $manager->openConnection('mysql://test@localhost/redcross_test');
    $manager->connection()->setCharset('utf8');
    $manager->setAttribute(Doctrine_Core::ATTR_TBLNAME_FORMAT, "redcross_%s");
}

function _Autoloader_TearDown() {
    Zend_Loader_Autoloader::resetInstance();
}
/*
 * This will nearly kill the server instance.
 *
 */
require_once 'Zend/Application.php';
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()->run();
//$bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
//_initAcl();
/* */

/**
 * Init autoloader
 */
_Autoloader_SetUp();

/**
 * Store application root in registry
 */
Zend_Registry::set('testRoot', $root);


/**
 * Start session now!
 */
Zend_Session::$_unitTestEnabled = true;
Zend_Session::start();

?>
